package servlet_formulaire;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.PersonnesManager;

/**
 * Servlet implementation class Verif_users
 */
public class Verif_users extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Verif_users() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PersonnesManager ref = null;
		
		Hashtable<String, String> h = new Hashtable<String, String>();
		h.put("java.naming.factory.initial",
				"org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
		h.put("java.naming.provider.url", "rmi://localhost:1099");
		h.put("java.naming.factory.url.pkgs", "org.objectweb.jonas.naminsg");
		Context ctx;
		try {
			ctx = new InitialContext(h);
			String JNDI_NAME = "managers.PersonnesManagerBean" + "_" + PersonnesManager.class.getName() + "@Remote";
			ref = (PersonnesManager) ctx.lookup(JNDI_NAME);
		} catch (NamingException e) {e.printStackTrace();}
		
		PrintWriter out = response.getWriter();
		out.print(""+ref.IsLoginUser(request.getParameter("login")));
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
